package com.zirenx.common.config;

import java.util.List;

import com.jfinal.config.Routes;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.jfinal.log.Log;
import com.zirenx.annotation.ClassScaner;
import com.zirenx.annotation.RouteMapping;

public class AdminRoutes extends Routes {

	public final String urlPrefix = "/admin";
	
	private static final Log log = Log.getLog(AdminRoutes.class);
	
	@SuppressWarnings("unchecked")
	@Override
	public void config() {
		//针对一组路由配置baseViewPath
		this.setBaseViewPath("/WEB-INF/admin");
		//针对一组路由配置单独的拦截器
		//this.addInterceptor(new AdminAuthInterceptor());
		//针对后台管理系统配置路由+controller
		
		 List<Class<RouteMapping>> controllerClassList = ClassScaner.scanAnnotationClass(RouteMapping.class);

		 if (controllerClassList != null) {
			for (Class<?> clazz : controllerClassList) {
				RouteMapping urlMapping = clazz.getAnnotation(RouteMapping.class);
				String value = urlMapping.value();
				if (null != urlMapping) {
					String controllerKey = urlPrefix + value;
					this.add(controllerKey, (Class<? extends Controller>) clazz, value);
					String msg = controllerKey+" "+clazz+" "+ value;
					log.info(msg);
				}
			}
		}
		
//		this.add("/admin/sys/dept", SysDeptController.class,"/sys/dept");
	}

}